<template>
  <!-- 数据集生成 -->
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="电解槽">
              <j-select-data-slot
                placeholder="请选择槽号"
                :multi="true"
                :buttons="false"
                v-model="queryParam.dataSoltIds"
              ></j-select-data-slot>
            </a-form-item>
          </a-col>
          <a-col :xl="6" :lg="11" :md="12" :sm="24">
            <a-form-item label="日期">
              <!-- <j-date placeholder="开始日期" class="query-group-cust" v-model="queryParam.recorddate_begin"></j-date>
              <span class="query-group-split-cust"></span>
              <j-date placeholder="结束日期" class="query-group-cust" v-model="queryParam.recorddate_end"> </j-date> -->
              <a-range-picker v-model="queryParam.startEndDate" />
            </a-form-item>
          </a-col>
          <a-col :xl="4" :lg="7" :md="8" :sm="24">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="handleSearch" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px" v-if="false"
                >重置
              </a-button>
              <a-button @click="handleAdd" type="primary" style="margin-left: 8px" v-if="dataSource.length > 0"
                >保存数据集</a-button
              >
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- table区域-begin -->
    <div>
      <!-- <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择 <a style="font-weight: 600">{{ selectedRowKeys.length }}</a>项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
      </div> -->

      <a-table
        ref="table"
        size="middle"
        bordered
        rowKey="id"
        class="j-table-force-nowrap"
        :scroll="{ x: true }"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        @change="handleTableChange"
      >
        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>

          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link"
              >更多
              <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a @click="handleDetail(record)">详情</a>
              </a-menu-item>
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <build-modal ref="modalForm" @ok="modalFormOk"></build-modal>
  </a-card>
</template>

<script>
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import '@/assets/less/TableExpand.less'
import BuildModal from './BuildModal'
import JSelectDataSlot from '@/components/jeecgbiz/JSelectDataSlot2'
import moment from 'moment'
import { httpAction, getAction } from '@/api/manage'
export default {
  name: 'DataSetBuild',
  mixins: [JeecgListMixin],
  components: {
    JSelectDataSlot,
    BuildModal,
  },
  data() {
    return {
      description: '数据集生成',
      disableMixinCreated: true,
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          },
        },
        {
          title: '槽号',
          align: 'center',
          dataIndex: 'slot_id',
        },
        {
          title: '时间',
          align: 'center',
          dataIndex: 'date',
          customRender: function (text) {
            return !text ? '' : text.length > 10 ? text.substr(0, 10) : text
          },
        },
        {
          title: '电流',
          align: 'center',
          dataIndex: 'electric',
        },
        {
          title: '电压',
          align: 'center',
          dataIndex: 'volt',
        },
        {
          title: '电阻',
          align: 'center',
          dataIndex: 'resistance',
        },
        {
          title: '滤波电阻',
          align: 'center',
          dataIndex: 'filter_res',
        },
        {
          title: '平滑电阻',
          align: 'center',
          dataIndex: 'smooth_res',
        },
        {
          title: '针震值',
          align: 'center',
          dataIndex: 'vibration',
        },
        {
          title: '摆动值',
          align: 'center',
          dataIndex: 'swing',
        },
        {
          title: '斜率mv',
          align: 'center',
          dataIndex: 'slope',
        },
        {
          title: '累斜',
          align: 'center',
          dataIndex: 'accsloper',
        },
        {
          title: '下料间隔时间',
          align: 'center',
          dataIndex: 'real_nb_interval',
        },
        {
          title: '纯手动操作状态',
          align: 'center',
          dataIndex: 'pure_man_operation',
        },
        {
          title: '电压上限',
          align: 'center',
          dataIndex: 'volt_upper_limit',
        },
        {
          title: '电压下限',
          align: 'center',
          dataIndex: 'volt_lower_limit',
        },
        {
          title: '设定下料间隔',
          align: 'center',
          dataIndex: 'set_nb_interval',
        },
        {
          title: '效应距今',
          align: 'center',
          dataIndex: 'reaction_interval',
        },
        {
          title: '母綫位移狀態',
          align: 'center',
          dataIndex: 'bus_put_up',
        },
        {
          title: '当前的设定电压值',
          align: 'center',
          dataIndex: 'volt_set',
        },
        {
          title: '下料模式',
          align: 'center',
          dataIndex: 'nb_mode',
        },
        {
          title: '母线位移值',
          align: 'center',
          dataIndex: 'pole_move_value',
        },
        {
          title: '正常下料次数',
          align: 'center',
          dataIndex: 'norm_nb_times',
        },
        {
          title: '阳极位移01',
          align: 'center',
          dataIndex: 'pole_move_01',
        },
        {
          title: '阳极位移02',
          align: 'center',
          dataIndex: 'pole_move_02',
        },
      ],
      url: {
        list: '/feature/rawData',
      },
      dictOptions: {},
      superFieldList: [],
      queryParam: {
        dataSoltIds: [],
      },
    }
  },
  created() {
    this.getSuperFieldList()
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    initDictConfig() {},
    getSuperFieldList() {
      let fieldList = []
      fieldList.push({ type: 'string', value: 'formulaName', text: '公式名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'formulaContent', text: '内容', dictCode: '' })
      fieldList.push({ type: 'date', value: 'modifyDate', text: '修改日期' })
      fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
      fieldList.push({ type: 'int', value: 'seqNo', text: '序号，用于公式排序', dictCode: '' })
      fieldList.push({ type: 'string', value: 'userId', text: '创建人', dictCode: '' })
      this.superFieldList = fieldList
    },
    loadData(arg) {
      var that = this
      if (that.queryParam.dataSoltIds == undefined || that.queryParam.dataSoltIds.length == 0) {
        this.$message.warning('请选择槽号')
        return
      }
      that.queryParam.slotNo = that.queryParam.dataSoltIds.join(',')
      if (that.queryParam.startEndDate) {
        that.queryParam.startDate = moment(that.queryParam.startEndDate[0]).format('YYYY-MM-DD')
        that.queryParam.endDate = moment(that.queryParam.startEndDate[1]).format('YYYY-MM-DD')
      } else {
        this.$message.warning('请选择日期')
        return
      }
      //var param = Object.assign({}, that.queryParam)
      that.loading = true
      var url =
        this.url.list +
        '?slotNo=' +
        that.queryParam.slotNo.trim() +
        '&startDate=' +
        that.queryParam.startDate +
        '&endDate=' +
        that.queryParam.endDate +
        '&pageNo=' +
        that.ipagination.current +
        '&pageSize=' +
        that.ipagination.pageSize
      getAction(url)
        .then((res) => {
          if (res.success) {
            this.dataSource = res.result.records || res.result
            if (res.result.total) {
              this.ipagination.total = res.result.total
            } else {
              this.ipagination.total = 0
            }
          } else {
            this.$message.warning(res.message)
          }
        })
        .finally(() => {
          that.loading = false
        })
    },
    handleSearch() {
      this.loadData()
    },
    handleAdd: function () {
      var that = this
      this.$refs.modalForm.add()
      this.$refs.modalForm.title = '保存数据集'
      this.$refs.modalForm.disableSubmit = false
      this.$refs.modalForm.model.dataSize = that.ipagination.total
      this.$refs.modalForm.model.slotNo = that.queryParam.slotNo.trim()
      this.$refs.modalForm.model.beginDate = that.queryParam.startDate
      this.$refs.modalForm.model.endDate = that.queryParam.endDate
    },
  },
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>